package com.mx.project.services.impl;

import com.mx.project.dao.UserMapper;
import com.mx.project.pojo.User;
import com.mx.project.vo.UserInfo;
import com.mx.project.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findUserByUid(Integer uid) {
        return userMapper.selectByPrimaryKey(uid);
    }

    @Override
    public int addUser(User user) {
        return userMapper.insertSelective(user);
    }

    @Override
    public User findUserByUserInfo(User user) {
        return userMapper.selectByUserInfo(user);
    }

    @Override
    public User findUserByUsername(String username) {
        return userMapper.selectUserByUsername(username);
    }

    @Override
    public User findUserByEmail(String email) {
        return userMapper.selectUserByEmail(email);
    }

    @Override
    public User findUserByPhone(String phone) {
        return userMapper.selectUserByPhone(phone);
    }

    @Override
    public User checkPassword(String username, String password) {
        return userMapper.selectUserByUP(username,password);
    }

    @Override
    public int updateUserInfo(User user) {
        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public boolean uploadNativeAvatar(File f) {
        return false;
    }

    @Override
    public UserInfo findUserInfoByUid(int uid) {
        return userMapper.selectUserInfoByUid(uid);
    }

    @Override
    public int updateAvatarByUid(Integer uid, String avatar) {
        User user = new User();
        user.setUid(uid);
        user.setAvatar(avatar);
        return userMapper.updateByPrimaryKeySelective(user);
    }

}
